﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//
using System.Timers;
/// <summary>
/// Summary description for clsAutoStart
/// </summary>
public class clsAutoStart
{
    public static void fncAutoStartOn()
    {
        //Code that runs on application startup
        System.Timers.Timer myTimer = new System.Timers.Timer();
        // Set the Interval to 5 seconds (5000 milliseconds).
        myTimer.Interval = Convert.ToDouble(OsPortal.oStringHelper.fncGetAppSettings("SPACE_TIME_CHECK_UP_TIN"));
        myTimer.AutoReset = true;
        myTimer.Elapsed += new System.Timers.ElapsedEventHandler(xAutoUptin);
        myTimer.Enabled = true;
    }

    /// <summary>
    /// Kiểm tra tin chưa up và up ngay
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    public static void xAutoUptin(object source, ElapsedEventArgs e)
    {
        // use your mailer code 
        int intCount = clsPhongTro.Auto_UpTin();
        try
        {
            //Write Log
            string strPathLog = OsPortal.oStringHelper.fncGetAppSettings("PATH_LOG_AUTO_UPTIN");
            string strNewContent = DateTime.Now.ToString() + " => " + intCount + " tin được up lên";
            OsPortal.oFileHelper.WriteFileAppend(strNewContent, strPathLog);
        }
        catch (Exception ex) {
            OsPortal.oFileHelper.WriteLogErr("clsAutoStart", "xAutoUptin", ex.ToString());
        }
    }
}